package com.lun.swordtowardoffer2.c11;

public class MySqrt {
	
	public int mySqrt(int num) {
		int left = 1, right = num;
		
		while(left <= right) {
			int mid = left + (right - left) / 2;
			
			if(mid <= num / mid) {
				if((mid + 1) > num / (mid + 1)) {
					return mid;
				}
				left = mid + 1;
			}else {
				right = mid - 1;
			}
		}
		
		return 0; 
	}
}
